<?php
include_once('common/header.php');
$strRefer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
if($AppUI->id <= 0 || $strRefer == '') {
	$arrJson 	= array('error'=>1,'msg'=>$arrError[3]);
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
	exit();
}
$intAction 		= $objRequest->getParam('act',null);
$strContent 	= $objRequest->getParam('content',null);
$intUblastId 	= $objRequest->getParam('ublastid',null);
$intUbcommentId	= $objRequest->getParam('ubcommentid',null);
$intLs			= $objRequest->getParam('ls',1);
$intError		= 0;
$strLink		= '';
if($intAction == 0 || !isset($intAction)) {
	if(trim($strContent) == '' || !isset($strContent)) $intError = 7;
	elseif(strlen($strContent) < 2) $intError = 8;
}
if($intError == 0) {
	$objFullhouse 	= new Fullhouse();
	$strMessage		= '';
	$intLike		= 0;
	if($intAction == 0 || !isset($intAction)) {
		$intAction = 0;
		$objFullhouse->addCmt($AppUI->id, $intUblastId, Vfriend_Function::stripTags($strContent,2));
		if($intLs > 1) {
			Vfriend_Function::deleteCookie('ubcmt' . $intUblastId);
		}
		$strMessage	= $arrMessage[1];
	}
	elseif(isset($intAction) && $intAction == 1) {
		$intError = $objFullhouse->deleteCmt($AppUI->id, $intUblastId, $intUbcommentId);		
		if($intLs > 1) {
			Vfriend_Function::deleteCookie('ubcmt' . $intUblastId);
		}
		if($intError > 0) $intError = 4; 
		else $strMessage = $arrMessage[2];
	}
	elseif(isset($intAction) && $intAction == 2) {
		$intError 	= $objFullhouse->likeCmt($AppUI->id, $intUblastId, $intUbcommentId, $intLike);		
		if($intError > 0) {
			if($intError == 3) $intError = 12;
			else $intError += 4;
		} else $strMessage = $arrMessage[3];
	}
	elseif(isset($intAction) && $intAction == 3) {
		$intError 	= $objFullhouse->addLike($AppUI->id, $intUblastId, $intLike);		
		if($intError > 0) $intError += 8;
		else $strMessage = $arrMessage[4];
	}
	elseif(isset($intAction) && $intAction == 4) {
		$intError	= $objFullhouse->delete($AppUI->id,$intUblastId);
		if($intError == 0) {
			$strMessage = $arrMessage[7];
			$strLink	= Vfriend_Function::linkFullHouse($AppUI->username, $AppUI->hex, $AppUI->fullnamevn);
		} else {
			$intError = 21;
		}
	}
	if($intError == 0) {
		if(isset($intAction) && $intAction < 3) {
			include_once('fullhouse/ublast-comment.php');
			$objView	= Zend_Registry::get('objView');
			$strData	= $objView->fetch('fullhouse/box-ublast-comment.tpl');
		}elseif(isset($intAction) && $intAction == 4) {
			$intUserProId	= $AppUI->id;
			include_once('fullhouse/box-ublast.php');
			$objView		= Zend_Registry::get('objView');
			$strData		= $objView->fetch('fullhouse/box-ublast.tpl');
		} else {
			$strData	= '';
			$intTotal	= 0;
		}
		$arrJson		= array('error'	=> 0, 
								'data'	=> $strData,
								'msg'	=> $strMessage,
								'like'	=> Vfriend_Function::numberFormat($intLike), 
								'total' => Vfriend_Function::numberFormat($intTotal),
								'link'	=> $strLink);
		echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
		exit();
	}
}
if($intError > 0) {
	$arrJson 	= array('error'=>1,'msg'=>$arrError[$intError]);
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
	exit();
}
?>
